﻿namespace Hotel.Module.Resources.Models
{
    using System;
    using Entities = Hotel.Module.Resources.DataRepository;

 
    public class Card : Model.Infrastructure.IDistributedStorageEntity
    {
        /// <summary>
        /// Creates a new Instance of Card according to recived Entity Card instance
        /// </summary>
        /// <param name="entity">Entity Card object from which new Card instance will be created</param>
        public static Card FromEnityModel(Entities.Card entity)
        {
            Card result = new Card();
            if (entity == null)
            {
                return null;
            }
            else
            {
                result.ExpireDate = entity.ExpireDate;
                result.ID = entity.Id;
                result.OrderID = entity.OrderID;
                result.State = (CardState)entity.State;               
            }
            return result;
        }
        /// <summary>
        /// Card identification number
        /// </summary>
        public int ID { get; set; }

        /// <summary>
        /// for permiting of card using
        /// </summary>
        public CardState State { get; set; }

        /// <summary>
        /// date of card expiration
        /// </summary>
        public DateTime ExpireDate { get; set; }

        /// <summary>
        /// Porperty for recieving the Order by card, contains identificational number of Order to which the room woner of card is assosiated wtih
        /// </summary>
        public int OrderID { get; set; }

        public string PartitionKey { get; set; }

        public string RowKey { get; set; }

        public DateTime Timestamp { get; set; }

        /// <summary>
        /// Assignes to recieved object data from current instnce
        /// </summary>
        /// <param name="obj">Object to which the data of current insctnce will be copied</param>
        public void AssignTo(object obj)
        {
            if (obj is Entities.Card)
            {
                Entities.Card result = obj as Entities.Card;

                result.ExpireDate =ExpireDate;
                result.Id = ID;
                result.OrderID = OrderID;
                result.State = (int)State;
                return;
            }

            throw new NotSupportedException();
        }
    }
}
